package com.pratik.gedcom;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import com.pratik.gedcom.parser.interfaces.GedcomParser;

public class GedcomToXmlFileConvertor {

	private GedcomParser gedcomParser;

	public File covertToXMLFile(File gedcomFile, String filepath) throws FileNotFoundException {
		File xmlFile = new File(filepath);
		String xmlString = gedcomParser.getGedcome(gedcomFile).getXMLString();
		writeFile(xmlFile, xmlString);
		return xmlFile;
	}

	private void writeFile(File xmlFile, String xmlString)
			throws FileNotFoundException {
		PrintWriter printWriter=new PrintWriter(xmlFile);
		printWriter.print(xmlString);
		printWriter.flush();
	}

	public void setGedcomParser(GedcomParser gedcomeParser) {
		this.gedcomParser=gedcomeParser;
	}

}
